package com.jh.paymentchannel.repository;

import java.util.List;

import com.jh.paymentchannel.pojo.Spend;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

@Repository
public interface SpendRepository extends JpaRepository<Spend,Long>,JpaSpecificationExecutor<Spend>{

	List<Spend> findByOrderCode(String orderCode);
	
	List<Spend> findByUserId(String userId);
	
	List<Spend> findBybindId(String bindId);
	
	Spend findByorderSon(String orderSon);
	
	Spend findById(long id);

	Spend findByOrderCodeAndAmount(String orderCode, String amount);
	
	@Query(value="select id,batch_no,pay_card,user_id,bind_id,order_code,order_son,execution_time,amount,status,message from t_spend where execution_time between ?1 and ?2 and status='0'",nativeQuery = true)
	List<Spend> findByExecutionTime(String start, String end);
	
	@Query(value="select id,batch_no,pay_card,user_id,bind_id,order_code,order_son,execution_time,amount,status,message from t_spend where execution_time between ?1 and ?2 and status='5'",nativeQuery = true)
	List<Spend> findByExecutionTimeandStatus(String start, String end);

	@Query(value="select spend from Spend spend where spend.batchNo=:batchNo")
	List<Spend> findTaskByBatchNo(@Param("batchNo") String batchNo);
	
}
